package acm.usa2000.midcentral;

import java.util.Scanner;
import java.util.Stack;

/*
 * p1913
 * ACM Mid Central USA 200
 */

public class p1913 {

	static Stack<String> stack;
	static BST tree;
	static String str;
	
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		
		stack = new Stack<String>();
		do {
			str = scanner.nextLine();
			if (str.startsWith("*")) {
				buildTree();
				printTree();
				System.out.println();
			}
			else if (str.startsWith("$")) {
				buildTree();
				printTree();
				System.out.println();
				break;
			}
			else {
				stack.add(str);
			}
		} while (true);

	}

	private static void printTree() {
		tree.preorder();
	}

	private static void buildTree() {
		String sroot = stack.pop();
		tree = new BST(sroot.charAt(0));
		while (!stack.isEmpty()) {
			String s = stack.pop();
			int len = s.length();
			for (int i=0;i<len;++i) {
				tree.add(s.charAt(i));
			}
		}
	}

}

class BST {
	char root;
	BST left, right;
	BST(char root) {
		this.root = root;
		this.left = this.right = null;
	}
	public void preorder() {
		System.out.print(root);
		if (left != null) {
			left.preorder();
		}
		if (right != null) {
			right.preorder();
		}
	}
	void add(char c) {
		if (c < root) {
			if (left == null) {
				left = new BST(c);
			}
			else {
				left.add(c);
			}
		}
		else if (c > root) {
			if (right == null) {
				right = new BST(c);
			}
			else {
				right.add(c);
			}
		}
	}
}
